//
//  MyAccountInforVCNew.m
//  NtoccShipper
//
//  Created by mac on 2020/6/10.
//  Copyright © 2020 zhuchongjin. All rights reserved.
//

#import "MyAccountInforVCNew.h"
#import "TiXianApplyVC.h"
#import "TradingRecordVC.h"
#import "CashDepositVC.h"
#import "WalletInfoVC.h"
#import "AccountBalanceModel.h"

@interface MyAccountInforVCNew ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) CJTableView *tableView;
//@property (nonatomic,copy)NSArray *arrImgs;
@property (nonatomic,copy)NSArray *arrTitles;
@property (weak, nonatomic) IBOutlet UIImageView *imgVHeader;
@property (weak, nonatomic) IBOutlet UILabel *labMoney;
@property (nonatomic,copy) NSString *strPingTaiMoney;
@property (nonatomic,strong) NSString *strWangShangMoney;

@end

@implementation MyAccountInforVCNew

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:CJLString(@"账户信息")];
    [self setBackLeftButton:@""];
    self.strPingTaiMoney = @"";
    self.strWangShangMoney = @"";
    self.labMoney.font = [UIFont boldSystemFontOfSize:36];
    [self.view addSubview:self.tableView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    [self getUSerInfo];
    [self getAccounBalance];
}
/// 获取账户余额
- (void)getAccounBalance{
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/collectionAccountCheck/balance",CJBaseUrl);
    NSDictionary *dicPar = [[NSDictionary alloc]init];
    WS(ws);
    [[HDNetworking sharedHDNetworking] GET:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
         // platformBalance  平台
        // mybankBalance 网商
//        DLog(@"++++++++%@",responseObject);
        NSError * error ;
        AccountBalanceModel *model = [[AccountBalanceModel alloc]initWithDictionary:responseObject error:&error];
        ws.strPingTaiMoney = @(model.platformBalance).cj_money_description;
        ws.strWangShangMoney = @(model.mybankBalance).cj_money_description;
//        ws.labMoney.text = CJStringWithFormat(@"%0.2f",model.platformBalance + model.mybankBalance);
        double allMoney = model.platformBalance + model.mybankBalance;
        ws.labMoney.text = @(allMoney).cj_money_description;

        [ws.tableView reloadData];
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];
}
//- (void)getUSerInfo{
//
//        NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/collectionAccountCheck/balance",CJBaseUrl);
//        NSDictionary *dicPar = [[NSDictionary alloc]init];
//        WS(ws);
//        [[HDNetworking sharedHDNetworking] GET:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
//             // platformBalance  平台
//            // mybankBalance 网商
//    //        DLog(@"++++++++%@",responseObject);
////            ws.strPingTaiMoney = @([[CJControl getThreeUnaryValueStr:responseObject[@"platformBalance"]] floatValue]).cj_description;
////            ws.strWangShangMoney = @([[CJControl getThreeUnaryValueStr:responseObject[@"mybankBalance"]] floatValue]).cj_description;
//
//            ws.labMoney.text = @([[CJControl getThreeUnaryValueStr:responseObject[@"platformBalance"]] floatValue] + [[CJControl getThreeUnaryValueStr:responseObject[@"mybankBalance"]] floatValue]).cj_description;
//
////            [ws.tableView reloadData];
//        } failure:^(NSError * _Nonnull error) {
//            DLog(@"++++++++%@",error);
//
//        }];
//
//}

#pragma mark----tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //return self.titles.count+ 1;
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrTitles.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *MeViewCellId = @"cellId";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MeViewCellId];
  if (cell ==nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:MeViewCellId];
      
      if (indexPath.row != 0) {
          cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      }
      cell.selectionStyle = UITableViewCellSelectionStyleNone;
      cell.textLabel.font = [UIFont cjTitleFont15];
      cell.textLabel.textColor = [UIColor cjMainTextColor];
  }
  
  if (indexPath.row == 0) {
      cell.detailTextLabel.text = [self.strPingTaiMoney isEqualToString:@""] ? @"0":self.strPingTaiMoney;
  }else if (indexPath.row == 1) {
      cell.detailTextLabel.text = [self.strWangShangMoney isEqualToString:@""] ? @"0":self.strWangShangMoney;// self.strWangShangMoney;
  }
  cell.textLabel.text = self.arrTitles[indexPath.row];
  return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
        UIViewController *vc;
        if (indexPath.row == 2) {
            vc = [TradingRecordVC new];
        }else if (indexPath.row == 1){
            vc = [WalletInfoVC new];
        }
        [self pushVc:vc];
}

- (CJTableView *)tableView{
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, self.imgVHeader.bottom + CJTableToTopHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kTopHeight  - self.imgVHeader.height - CJTableToTopHeight),UITableViewStylePlain)
        .tbDelegate(self)
        .tbDataSource(self)
        .tbSetOther(YES)
        .tbEstimatedRowHeight(YES)
//        .tbMjHeadFooter(YES)
        ;

    }
    
    return _tableView;
}

- (NSArray *)arrTitles{
    
    if(!_arrTitles){
        _arrTitles = @[@"平台余额",@"网商余额",@"交易记录"];//,@"提现申请"
    }
    return _arrTitles;
}

//- (NSArray *)arrImgs{
//    if(!_arrImgs){
//        _arrImgs = @[@"zcj_icon_record",@"zcj_icon_feeInfo"];
//    }
//    return _arrImgs;
//}

@end
